#ifndef CLIENTTCP_H
#define CLIENTTCP_H
#include <QObject>
#include <QThread>
#include <QTcpSocket>
#include <QByteArray>
#include <QMutex>
#include <QTimer>
class ClientTcp : public QObject
{
    Q_OBJECT
public:
    explicit ClientTcp(QObject *parent = nullptr);
    ~ClientTcp();
    void startLogin(const QString &tempUsername, const QString &tempPassword);
signals:
    void loginResult(bool success);
private slots:
    void onReadyRead();
    void onError(QAbstractSocket::SocketError socketError);
private:
    void handleLogin(const QString &user, const QString &pass);
    void cleanupResources();
    void handleError(const QString &msg);
    QThread *m_workerThread;
    QTcpSocket *m_socket;
    QByteArray m_readBuffer;
    QMutex m_mutex;

    QTimer *m_connectTimer;
    QTimer *m_responseTimer;
    static const QString SERVER_ADDRESS;
    static const quint16 SERVER_PORT;
    static const int CONNECT_TIMEOUT_MS;
    static const int RESPONSE_TIMEOUT_MS;
};
#endif // CLIENTTCP_H
